<template>
	<view class="recharge">
		<view class="recharge-title">
			充值金额
		</view>

		<view class="recharge-money">
			<view class="recharge-money-item" v-for="(item,index) in moneyList" :key="index"
				:class="activeIndex == index?'active':''" @click="selectMoney(index)">
				<view class="recharge-item-money">
					{{ item.reachPrice }}<span>元</span>
				</view>

				<view class="recharge-item-tip">
					送{{ item.givePrice }}
				</view>
			</view>

		</view>

		<view class="recharge-title h-m-t-20">
			充值说明
		</view>
		<view class="recharge-tip">
			<view>1.充值所得金额仅该店铺可用可用。</view>
			<view>2.该充值功能仅在本公众号可用。</view>
			<view>3.充值金额可享受折上折。</view>
		</view>

		<view class="recharge-buttom-box">
			<view class="buttom-left">
				<view class="buttom-left-info">付款金额</view>
				<view class="buttom-left-money" v-if="moneyList.length != 0">¥ {{ moneyList[activeIndex].reachPrice }}</view>
			</view>

			<view class="buttom-right" @click="okEvent">
				立即充值
			</view>
		</view>

	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex';
	import wxPay from '@/common/mixins/wxPay.js';
	export default {
		data() {
			return {
				moneyList: [],
				activeIndex: 0,
				shopId: undefined,
			};
		},
		computed: {
			...mapState(['hasLogin', 'userInfo'])
		},
		// 混入微信支付
		mixins: [wxPay],
		onLoad(e) {
			this.shopId = e.shopId
			this.getShopRule(e.shopId);
		},
		methods: {
			// 获取店铺充值规则
			getShopRule(shopId) {
				this.$u.api.getShopRule({
					shopId,
					type: 2
				}).then(res => {
					console.log(res, 'res');
					this.moneyList = res.dataList;
				})
			},
			/* 选择充值金额 */
			selectMoney(index) {
				this.activeIndex = index
			},
			async okEvent() {
				const data = {
					shopId: this.shopId,
					userId: this.userInfo.id,
					rechargePrice: this.moneyList[this.activeIndex].reachPrice,
					giftsPrice: this.moneyList[this.activeIndex].givePrice,
				}
				const outTradeNoInfo = await this.$u.api.rechargeShopSaveUser({...data});
				const outTradeNo = outTradeNoInfo.data;
				// 储蓄支付的额外值
				const attach = data;
				// #ifdef H5
				this.entPay(outTradeNo, data.rechargePrice, 1, {...attach});
				// #endif
			}
		}
	}
</script>

<style lang="scss">
	.recharge {
		margin: 30rpx;

		.recharge-title {
			color: #333333;
			font-weight: bold;
		}

		.recharge-tip {
			margin-top: 20rpx;

			view {
				font-size: 28rpx;
				color: #666666;
				margin-top: 10rpx;
			}
		}

		.recharge-money {
			display: flex;
			align-items: center;
			overflow: hidden;
			overflow-x: scroll;
			margin-top: 10rpx;

			.recharge-money-item:first-child {
				margin-left: 0;
			}

			.recharge-money-item {
				margin: 20rpx 10rpx;
				width: 280rpx;
				height: 360rpx;
				border: 2rpx solid #efefef;
				border-radius: 30rpx;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				box-sizing: border-box;
				box-shadow: #f0f0f0 0px 1px 8px 0;
				flex-shrink: 0;

				.recharge-item-money {
					font-size: 60rpx;
					color: #333;

					span {
						font-size: 28rpx;
					}
				}

				.recharge-item-tip {
					padding: 6rpx 20rpx;
					font-size: 24rpx;
					background: #efefef50;
					border-radius: 40rpx;
					margin-top: 20rpx;
					color: #666666;
				}
			}

			.active {
				background-image: url("");
				background-size: 100% 100%;
				background-repeat: no-repeat;
				border: none;
			}
		}

		.recharge-buttom-box {
			position: fixed;
			bottom: 0;
			width: calc(100vw - 60rpx);
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding-bottom: 80rpx;
			padding-top: 20rpx;
			border-top: 2rpx dashed #efefef;
			box-sizing: border-box;

			.buttom-left {
				font-size: 28rpx;
				display: flex;
				align-items: flex-end;

				.buttom-left-money {
					font-weight: bold;
					font-size: 40rpx;
					margin-left: 20rpx;
					line-height: 38rpx;
				}

				.buttom-left-money::first-letter {
					font-weight: normal;
					font-size: 28rpx;
				}
			}

			.buttom-right {
				padding: 16rpx 58rpx;
				background: #333;
				color: #fff;
				border-radius: 50rpx;
				font-size: 28rpx;
				font-weight: bold;
			}
		}
	}
</style>